---
hide_table_of_contents: true
sidebar_class_name: hidden
---

import CodeBlock from "@theme/CodeBlock";

# OpenAPI Calls

:::tip Compatibility
Must be used with an [OpenAI Functions](https://platform.openai.com/docs/guides/gpt/function-calling) model.
:::

This chain can automatically select and call APIs based only on an OpenAPI spec.
It parses an input OpenAPI spec into JSON Schema that the OpenAI functions API can handle.
This allows ChatGPT to automatically select the correct method and populate the correct parameters for the a API call in the spec for a given user input.
We then make the actual API call, and return the result.

## Usage

The below examples initialize the chain with a URL hosting an OpenAPI spec for brevity, but you can also directly pass a spec into the method.

### Query XKCD

import SimpleExample from "@examples/chains/openai_functions_openapi_simple.ts";

import IntegrationInstallTooltip from "@mdx_components/integration_install_tooltip.mdx";

<IntegrationInstallTooltip></IntegrationInstallTooltip>

```bash npm2yarn
npm install @langchain/openai
```

<CodeBlock language="typescript">{SimpleExample}</CodeBlock>

### Translation Service (POST request)

The OpenAPI chain can also make POST requests and populate bodies with JSON content if necessary.

import PostRequestExample from "@examples/chains/openai_functions_openapi_post.ts";

<CodeBlock language="typescript">{PostRequestExample}</CodeBlock>

### Customization

The chain will be created with a default model set to `gpt-3.5-turbo-0613`, but you can pass an options parameter into the creation method with
a pre-created `ChatOpenAI` instance.

You can also pass in custom `headers` and `params` that will be appended to all requests made by the chain, allowing it to call APIs that require authentication.

import CustomizationExample from "@examples/chains/openai_functions_openapi_customization.ts";

<CodeBlock language="typescript">{CustomizationExample}</CodeBlock>
